/**
 * Created by zl on 2017/4/13.
 */
angular.module('informationModule', [])
    .controller('informationCtrl', ['$scope','$informationService', '$sce', function ($scope, $informationService, $sce) {

        $scope.selectedMenu = 1;
        $scope.contentData = {};

        $scope.getInformationList = function () {
            $scope.selectedMenu = 1;
            $scope.showContent = false;
            $scope.locationStr = $sce.trustAsHtml('您当前的位置：公示信息>><span>财务支出公开</span>');
            $informationService.getAuditList().then(function (result) {
                if(result && result.code == 0)
                {
                    $scope.auditList = result.data;
                }

            });
        }
        
        $scope.getTrackInfo = function () {
            $scope.selectedMenu = 2;
            $scope.locationStr = $sce.trustAsHtml('您当前的位置：公示信息>><span>救助活动追踪</span>');
            $informationService.getTrackList().then(function (result) {
                if(result && result.code == 0)
                {
                    $scope.trackList = result.data;
                }
            });
        }
        
        $scope.showContentDetail = function (contentData) {
            $scope.selectedMenu = 3;
            $scope.locationStr = $sce.trustAsHtml('您当前的位置：公示信息>>救助活动追踪>><span>'+contentData.name+'</span>');
            $scope.contentData = contentData ;
            $scope.contentData.contentHtml = $sce.trustAsHtml(contentData.content);
        }

        $scope.getInformationList();

    }])
    .factory('$informationService', ['$http', function ($http) {
        return {
            getAuditList: function () {
                return $http({
                    method: 'GET',
                    url: '/audits/auditlist'
                }).then(function (result) {
                    return result.data;
                })
            },
            getTrackList: function () {
                return $http({
                    method: 'GET',
                    url: '/audits/tracklist'
                }).then(function (result) {
                    return result.data;
                })
            }
        }

    }]);